package com.ruoyi.chat.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.vo.AddFriendUserVO;
import org.springframework.stereotype.Service;
import com.ruoyi.chat.mapper.SysUserMapper;
import com.ruoyi.chat.domain.SysUser;
import com.ruoyi.chat.service.ISysUserService;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;

/**
 * 用户信息Service业务层处理
 * 
 * @author zhc
 * @date 2025-06-01
 */
@Service
public class SysUserServiceImpl implements ISysUserService 
{
    @Resource
    private SysUserMapper sysUserMapper;

    /**
     * 查询用户信息
     * 
     * @param userId 用户信息主键
     * @return 用户信息
     */
    @Override
    public SysUser selectSysUserByUserId(Long userId)
    {
        return sysUserMapper.selectSysUserByUserId(userId);
    }

    @Override
    public Map<String,SysUser> selectSysUserByUserIds(List<String> userIds) {
        return CollectionUtils.isEmpty(userIds)?new HashMap<>()
                :sysUserMapper.selectSysUserByUserIds(userIds).stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity()));
    }

    /**
     * 查询用户信息列表
     * 
     * @param sysUser 用户信息
     * @return 用户信息
     */
    @Override
    public List<SysUser> selectSysUserList(SysUser sysUser)
    {
        return sysUserMapper.selectSysUserList(sysUser);
    }

    /**
     * 新增用户信息
     * 
     * @param sysUser 用户信息
     * @return 结果
     */
    @Override
    public int insertSysUser(SysUser sysUser)
    {
        sysUser.setCreateTime(DateUtils.getNowDate());
        return sysUserMapper.insertSysUser(sysUser);
    }

    /**
     * 修改用户信息
     * 
     * @param sysUser 用户信息
     * @return 结果
     */
    @Override
    public int updateSysUser(SysUser sysUser)
    {
        sysUser.setUpdateTime(DateUtils.getNowDate());
        return sysUserMapper.updateSysUser(sysUser);
    }

    /**
     * 批量删除用户信息
     * 
     * @param userIds 需要删除的用户信息主键
     * @return 结果
     */
    @Override
    public int deleteSysUserByUserIds(Long[] userIds)
    {
        return sysUserMapper.deleteSysUserByUserIds(userIds);
    }

    /**
     * 删除用户信息信息
     * 
     * @param userId 用户信息主键
     * @return 结果
     */
    @Override
    public int deleteSysUserByUserId(Long userId)
    {
        return sysUserMapper.deleteSysUserByUserId(userId);
    }

    @Override
    public AddFriendUserVO selectSysUserByPhoneOrUserName(String cond) {
        return sysUserMapper.selectSysUserByPhoneOrUserName(cond);
    }
}
